package com.cmwa.solution.sys.schedule.controller;

import javax.annotation.Resource;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;

import com.cmwa.solution.base.controller.BaseController;
import com.cmwa.solution.base.entity.Page;
import com.cmwa.solution.base.entity.ScheduleVo;
import com.cmwa.solution.base.entity.SearchParam;
import com.cmwa.solution.sys.schedule.service.ScheduleService;

/**
 * 定时任务
 * @author ex-hejm
 * @date 2018年10月15日 上午10:54:26
 */
@Controller
@RequestMapping("/sys/schedule")
public class ScheduleController extends BaseController{
	private static final Log log = LogFactory.getLog(ScheduleController.class);
	
	@Resource
	private ScheduleService scheduleService;
	
	/**
	 * 定时任务列表页面
	 * 
	 * @return
	 */
	@RequestMapping("/scheduleListView")
	public String scheduleListView(ModelMap model) {
		return "system/sys/schedule/scheduleList";
	}
	
	/**
	 * 定时任务列表分页数据
	 * 
	 * @param sp
	 * @return
	 */
	@RequestMapping("/scheduleListPage")
	@ResponseBody
	public Page<ScheduleVo> scheduleListPage(SearchParam sp) {
		Page<ScheduleVo> list = scheduleService.scheduleListPage(sp);
		return list;
	}
	
	/**
	 * 定时任务状态改变
	 * 
	 * @return
	 */
	@RequestMapping("/updateScheduleStatus")
	public String updateScheduleStatus(ScheduleVo schedule) {
		scheduleService.updateScheduleStatus(schedule);
		return redirectSuccess();
	}
	
	/**
	 * 执行一次定时任务
	 * 
	 * @return
	 */
	@RequestMapping("/executeSchedule")
	public String executeSchedule(@RequestParam(value = "taskId") String taskId) {
		log.info("开始执行定时任务");
		scheduleService.executeSchedule(taskId);
		return redirectSuccess();
	}
}
